package com.oocl.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.oocl.dao.PurchaserDao;
import com.oocl.pojo.Purchaser;
import com.oocl.util.DBUtil;

public class PurchaserDaoImpl implements PurchaserDao{

	public Purchaser loadPurchase(Purchaser p) {
		String sql = "select * from purchaser where name = ? and pwd = ?";
		Purchaser purchaser = null;
		Connection con = null;
		PreparedStatement stat =null;
		ResultSet rs = null;
        try {
        	con = DBUtil.createConnection();
			stat = con.prepareStatement(sql);
			stat.setString(1, p.getName());
			stat.setString(2, p.getPwd());
			rs = stat.executeQuery();
			if(rs.next()){
				purchaser = new Purchaser();
				purchaser.setId(rs.getString("id"));
				purchaser.setName(rs.getString("name"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			DBUtil.close(con, stat, rs);
			
		}
		return purchaser;
	}

}
